package Hibernate.cn.edu.scau.cmi.lishuoxin.util;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class HibernateUtils {
	private static SessionFactory sf;
	
	static {
		//1.调用空参构造加载hibernate的配置信息，默认路径是src下
		Configuration conf = new Configuration().configure();
		//2.根据配置，创建SessionFactory对象
		sf = conf.buildSessionFactory();
	}
	
	//获得全新的session
	public static Session openSession() {
		Session session = sf.openSession();
		return session;
	}
	
	//获得与线程绑定的session
	public static Session getCurrentSession() {
		Session session = sf.getCurrentSession();
		return session;
	}
}

